import React ,{ Component }from 'react';
import { Menu, Dropdown } from 'antd';
import { DownOutlined } from '@ant-design/icons';
import './index.scss';
import { connect } from 'react-redux';
import * as actionCreators from '../../store/actionCreators';
import {withRouter,Link } from 'react-router-dom';
import CBreadCrumb from '../../comoponents/c-breadcrumb';
import {API_LIST} from "../../common/js/api";


class Index extends Component {
    constructor(props) {
        super(props);
    }
    componentDidMount() {

    }

    navigateTo(url) {
        this.props.history.push(url);
    }

    logout = () => {
        this.request({
            url: API_LIST.exit,
            tip: true,
            params: {},
            callback: (data) => {
                this.navigateTo('/login')
            },
            error: (data) => {
                this.setState({
                    menuList: data
                })
            }
        });
    }

    render() {
        const menu = (
            <Menu>
                <Menu.Item onClick={() => this.logout()}>
                    退出登录
                </Menu.Item>
            </Menu>
        );
        return (
            <React.Fragment>
                <div className="bread-crumb">
                    <CBreadCrumb></CBreadCrumb>
                </div>
                <div className="user">
                    <Dropdown overlay={menu}>
                        <a className="ant-dropdown-link" onClick={e => e.preventDefault()}>
                            超级管理员 <DownOutlined />
                        </a>
                    </Dropdown>
                </div>
            </React.Fragment>
        );
    }
}
const mapStateToProps = (state) => {
    return {
        loginUser: state.get('loginUser')
    }
}

const mapDispatchToProps = (dispatch) => ({
    setLoginUser(data) {
        const action = actionCreators.getLoginUser(data);
        dispatch(action);
    }
})
export default withRouter(connect(mapStateToProps,mapDispatchToProps)(Index));
